﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;

namespace logic
{
    public class company
    {       

        public static int insert(CompanyEntity cp)
        {
            return Company.insert(cp);
        }
        
        public static void update(CompanyEntity cp)
        {
            Company.update(cp);
        }

        public static bool updatePartialSeller(CompanyEntity companyInfo)
        {
            return Company.updatePartialSeller(companyInfo);
        }

        public static bool updatePartialBuyer(CompanyEntity companyInfo)
        {
            return Company.updatePartialBuyer(companyInfo);
        }

        //修改审核信息
        public static void updateByCheck(CompanyEntity cp)
        {
            Company.updateByCheck(cp);
        }

        public static void delete(int companyId)
        {
            Company.delete(companyId);
        }

        public static CompanyEntity getById(int companyId)
        {
            return Company.getById(companyId);
        }

        public static DataTable getType(int companyId)
        {
            return Company.getType(companyId);
        }

        public static DataTable getBuyRange(int companyId)
        {
            return Company.getBuyRange(companyId);
        }

        

        public static DataSet select(string where, string orderby, int pagesize, int pageindex)
        {
            return DAL.DbHelper.ExecuteDataSetPageSize("*", "vw_Company_list", where, "companyId", orderby, pagesize, pageindex);
        }

        /// <summary>
        /// 得到采购商的类别用来绑定 Repeater 中的 radio
        /// </summary>
        /// <param name="companyId">企业ID</param>
        /// <returns></returns>
        public static DataTable getBuyerTypeList(int companyId)
        {
            return Company.getBuyerTypeList(companyId);
        }

        /// <summary>
        /// 修改供应商的积分
        /// </summary>
        /// <param name="company"></param>
        public static void updateScore(int companyId,int score)
        {
            Company.updateScore(companyId,score);
        }

        /// <summary>
        /// 企业编号是否存在
        /// </summary>
        /// <param name="companyNo"></param>
        /// <returns></returns>
        public static bool isExistCompanyNo(string companyNo)
        {
            return Company.isExistCompanyNo(companyNo);
        }

        //删除企业
        public static void updateIsDel(CompanyEntity company)
        {
            Company.updateIsDel(company);
        }

        /// <summary>
        /// 根据类型得到企业信息
        /// </summary>
        /// <param name="companyType">类型：1、供应商；2、采购商</param>
        /// <returns>DataTable</returns>
        public static DataTable listWithCompanyType(string companyType)
        {
            return Company.listWithCompanyType(companyType);
        }

        /// <summary>
        /// 查询所有采购商企业【包括销售测试企业】
        /// </summary>
        /// <returns></returns>
        public static DataTable listWithCompanyTypeIncludeTest()
        {
            return Company.listWithCompanyTypeIncludeTest();
        }

         /// <summary>
        /// 根据报价模式查询供应商
        /// </summary>
        /// <param name="quotationMode">报价模式 1 表示自由报价模式；2 表示封闭报价模式</param>
        /// <returns></returns>
        public static DataTable listSellerByQuotationMode(string quotationMode)
        {
            return Company.listSellerByQuotationMode(quotationMode);
        }

        /// <summary>
        /// 查询启用周报价的企业
        /// </summary>
        /// <returns></returns>
        public static DataTable listWithWeeklyPrice()
        {
            return Company.listWithWeeklyPrice();
        }

        /// <summary>
        /// 根据年份查询企业周订购量
        /// </summary>
        /// <param name="companyId"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        public static DataTable listCompanyDataAnalysisByCriteria(int companyId, int year,string mode)
        {
            return Company.listCompanyDataAnalysisByCriteria(companyId, year,mode);
        }

        /// <summary>
        /// 根据年份查询企业月供应量
        /// </summary>
        /// <param name="companyId"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        public static DataTable listCompanyDataAnalysisSupplyByCriteria(int companyId, int year)
        {
            return Company.listCompanyDataAnalysisSupplyByCriteria(companyId, year);
        }

        public static DataTable listCompanyGPMAnalysisByCriteria(int companyId, int year, string mode, DateTime? startDt, DateTime? endDt)
        {
            return Company.listCompanyGPMAnalysisByCriteria(companyId, year, mode, startDt, endDt);
        }

        public static void P_CompanyIsdel(int cid)
        {
            Company.P_CompanyIsdel(cid);
        }

        public static void saveCompanyBusniessNature(int adminId,int companyId,string businessNatures)
        {
            SellerBusinessNature.Save(adminId, companyId, businessNatures);
        }

        public static DataTable getCompanyBusinessNature(int companyId)
        {
            return SellerBusinessNature.GetBusinessNaturesByCompanyId(companyId);
        }

        public static DataTable listSellerWithSellerRange()
        {
            return Company.listSellerWithSellerRange();
        }

        public static DataSet listCompanyGPMAnalysisList(int year,int month,string where, string orderByColumn, int pageSize, int pageIndex)
        {
            return DbHelper.ExecuteReDataSet("[dbo].[p_Company_DataAnalysis_List]", year,month, where, orderByColumn, pageSize, pageIndex);
        }

        public static DataTable exportCompanyGPMAnalysisToExcel(int year,int month,string orderByColumn)
        {
            return DbHelper.ExecuteDataTable("[dbo].[p_Company_exportCompanyGPMAnalysisToExcel]", year,month,orderByColumn);
        }

        public static bool listCompanyWeekWithByCompanyId(int companyid)
        {
            return Company.listCompanyWeekWithByCompanyId(companyid);
        }

        /// <summary>
        /// 查出某商品有哪几个供应商在供应
        /// </summary>
        /// <param name="productid"></param>
        /// <returns></returns>
        public static DataTable listSellerByProductId(int productid)
        {
            return Company.listSellerByProductId(productid);
        }
    }
}
